const { list } = require('./mock')
const bodyParser = require('body-parser')
module.exports = app => {
	app.use(bodyParser.json())
	app.post('/api/list', (req, res) => {
		const { isPerfect, desc, type } = req.body

		// 筛选是否精选
		const newList = [...list].filter(v => {
			return isPerfect ? v.isPerfect : true
		})
		// 是否排序
		.sort((a, b) => {
			if(desc === '综合') return 
			if(desc === '时间') return new Date(b.datetime).getTime() - new Date(a.datetime).getTime()
			if(desc === '评价') return b.score - a.score
			if(desc === '收藏') return b.collect - a.collect
		})
		// 多重筛选
		.filter(item => {
			return type.every((v) => {
				return item.type.some(item => {
					return item.name.includes(v)
				})
			})
		})
		

		res.send({
			code: 200,
			data: newList
		})
	})
}